package ru.evga.inse.core.dao.dict.impl;

import org.springframework.stereotype.Repository;

import ru.evga.inse.core.dao.DaoException;
import ru.evga.inse.core.dao.FindRangeContext;
import ru.evga.inse.core.dao.IResultContainer;
import ru.evga.inse.core.dao.dict.IStreetDao;
import ru.evga.inse.core.dao.impl.GenericDao;
import ru.evga.inse.core.domain.dict.Street;
import ru.evga.inse.core.filter.dict.StreetFilter;


@Repository
public class StreetDao
    extends GenericDao<Street>
    implements IStreetDao
{
    
    public IResultContainer<Street> findRange(
        Integer firstResult, 
        Integer maxResults,
        String orderBy, 
        Boolean isAsc, 
        StreetFilter filter)
        throws DaoException
    {
        FindRangeContext<Street> queryBuilder = new FindRangeContext<Street>(this);
        queryBuilder.setOrder(orderBy, isAsc);

        if (filter != null)
        {
            String nameFilter = filter.getName();
            if (nameFilter != null && nameFilter.length() > 0)
            {
                queryBuilder.addLike("name", nameFilter);
            }
        }
        
        return findRange(firstResult, maxResults, queryBuilder);
    }

}
